<template>
	<view>
		<u-navbar :border-bottom="false" back-icon-name="home" title-bold title="抢单中心" :custom-back="customBack"></u-navbar>
		<u-sticky>
			<!-- 只能有一个根元素 -->
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</u-sticky>
		<!-- 此处分开写，为了让数据互不影响 -->
		<template v-if="current === 0">
			<order-list :list="grabLists" :current="current" @getOrderTakeawayData='getOrderTakeawayData'></order-list>
		</template>
		<template v-if="current === 1">
			<rider-List :list="inserviceLists" :current="current" @getOrderTakeawayData='getOrderTakeawayData'></rider-List>
		</template>
		<template v-if="current === 2">
			<rider-List :list="inserviceLists" :current="current" @getOrderTakeawayData='getOrderTakeawayData'></rider-List>
		</template>
		<template v-if="current === 3">
			<rider-List :list="completedLists" :current="current" @getOrderTakeawayData='getOrderTakeawayData'></rider-List>
		</template>
		<!-- <template v-if="current === 3">
			<order-list :list="canceledLists" :current="current"></order-list>
		</template> -->
		<!-- <fui-fab :zIndex="10" distance="32" @click="fabClick">
			<u-icon name="scan" color="#fff" size="38"></u-icon>
		</fui-fab> -->
		<!-- <fui-single-input type="number" isFocus @input="onInput" @complete="onComplete"></fui-single-input> -->
	</view>
</template>

<script>
	import orderList from './components/order-list.vue';
	import riderList from './components/rider-list.vue';
	export default {
		props: {
			current: {
				type: [Number, String],
				default: 0
			}
		},
		data() {
			return {
				page:1,//页数
				list: [{
					name: '抢单大厅'
				}, {
					name: '取餐中',
				},{
					name: '配送中',
				}, {
					name: '已完成'
				} ],
				userInfo:{},
				grabLists: [],// 抢单中的数据
				inserviceLists: [],// 服务中的数据
				completedLists: [],// 已完成的数据
				canceledLists: [],// 已完成的数据
			}
		},
		components:{
			orderList,riderList
		},
		onShow(e) {
			if(!uni.getStorageSync('userInfo')){
				this.$ut.route('pages/login/login',{},'reLaunch');
			}
			this.userInfo = uni.getStorageSync('userInfo');
			console.log("userInfo",this.userInfo);
			if(this.userInfo.workType == null){
				this.$ut.route('pages/rider/index',{},'reLaunch');
			}
			if(this.userInfo.workType == 0){
				this.list = [
				{
					name: '取餐中',
				},{
					name: '配送中',
				}, {
					name: '已完成'
				} ];
			}else{
				this.list = [{
					name: '抢单大厅'
				}, {
					name: '取餐中',
				},{
					name: '配送中',
				}, {
					name: '已完成'
				} ];
			}
			this.getOrderTakeawayData();
			//console.log(e.current);
			// if(e.current) {
			// 	// 组件中用了全等，此处要转number
			// 	this.current = Number(e.current);
			// 	this.initData();
			// }
		},
		// 下拉刷新
		onPullDownRefresh(){
			this.page = this.page  + 1;
			this.getOrderTakeawayData();
		},
		methods: {
			// 扫码
			fabClick(){
				this.$u.toast('点击扫码');
				uni.scanCode({
					onlyFromCamera: true,
					success(res) {
						console.log(res);
					}
				})
			},
			// 获取订单
			getOrderTakeawayData(){
				if(this.current == 0){
					this.$u.api.getOrderTakeawayHallToDelivery({
						deliveryState: this.current,
						page:this.page
					}).then(res=>{
						this.grabLists = res.dataList;
					})
				}
				if(this.current == 1){
					this.$u.api.getOrderTakeaway({
						deliveryState: 1,
						deliveryId: uni.getStorageSync('userInfo').id,
						page:this.page
					}).then(res=>{
						this.inserviceLists = res.dataList;
					})
				}
				if(this.current == 2){
					this.$u.api.getOrderTakeaway({
						deliveryState: 2,
						deliveryId: uni.getStorageSync('userInfo').id,
						page:this.page
					}).then(res=>{
						this.inserviceLists = res.dataList;
					})
				}
				if(this.current == 3){
					this.$u.api.getOrderTakeaway({
						deliveryState: 3,
						deliveryId: uni.getStorageSync('userInfo').id,
						page:this.page
					}).then(res=>{
						this.completedLists = res.dataList;
					})
				}
			},
			initData(){
				this.getOrderTakeawayData();
			},
			change(index) {
				this.current = index;
				this.page = 1;
				this.getOrderTakeawayData();
			},
			// 跳转个人中心
			customBack() {
				this.$ut.route('pages/rider/index');
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>